/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;

/**
 *
 * @author psychok7
 */
public class MobileCache {
        
        public MobileCache(){

        }
        
        public String saveMobileCache(String xmlstr, String username ){
            
        try {
            RecordStore.deleteRecordStore("MobileUC_"+username);
        } 
        catch (RecordStoreException ex) {
            try {
                RecordStore rs = RecordStore.openRecordStore("MobileUC_"+username, true);
                byte bytes[] = xmlstr.getBytes();
                rs.addRecord(bytes,0,bytes.length);
                rs.closeRecordStore();
            } catch (RecordStoreException ex1) {
                ex1.printStackTrace();
            } 
                        
        } 
        
            try {
                RecordStore rs = RecordStore.openRecordStore("MobileUC_"+username, true);
                byte bytes[] = xmlstr.getBytes();
                rs.addRecord(bytes,0,bytes.length);
                rs.closeRecordStore();
            } catch (RecordStoreException ex1) {
                ex1.printStackTrace();
            }         
          

            return xmlstr;
            
        }
        
        
        public String loadMobileCache(String username) {
            String str=null;
        try {
            RecordStore rs = RecordStore.openRecordStore("MobileUC_"+username, true);
            byte b[] = rs.getRecord(1);
            str = new String(b,0,b.length);    
            rs.closeRecordStore();
        } 
        catch (RecordStoreException ex) {
            ex.printStackTrace();
        }

            return str;
    }
    
}
